import { defineStore } from 'pinia'
import menuList from "@/router/menu"
export const useMenu = defineStore('menu', {
    state: () => {
        navList: []
    },
    actions: {
        setNav(currentPath) {
            // todo 这个应该写一个递归
            // 先置空
            this.navList = []
            // 找到第一层级的路由
            const target = menuList.find((item) => {
                return currentPath.indexOf(item.path) > -1
            })
            // 推进去
            this.navList.push(target.title)
            // // 找到第二层级的路由
            const subTarget = target.children.find((child) => {
                return currentPath.indexOf(child.path) > -1
            })
            // 推进去
            this.navList.push(subTarget.title)
        }
    }
})